package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.RelationGoods;

import java.util.List;

/**
 * Created by lanouhn on 16/9/16.
 */
public class RelationGoodsAdapter extends BaseAdapter{
    private Context context;
    private List<RelationGoods.DataBean.ProductBean> detailsContent;

    public RelationGoodsAdapter(Context context, List<RelationGoods.DataBean.ProductBean> detailsContent) {
        this.context = context;
        this.detailsContent = detailsContent;
    }

    @Override
    public int getCount() {
        return detailsContent.size();
    }

    @Override
    public Object getItem(int position) {
        return detailsContent.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_relation_goods, null);
            holder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic_relation_goods_author);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title_relation_goods_author);
            holder.tv_likes = (TextView) convertView.findViewById(R.id.tv_likes_relation_goods_author);
            holder.tv_price= (TextView) convertView.findViewById(R.id.tv_price_relation_goods_author);
            convertView.setTag(holder);
        } else {
            holder= (ViewHolder) convertView.getTag();
        }
        RelationGoods.DataBean.ProductBean bean=detailsContent.get(position);
        Picasso.with(context).load(bean.getPic()).into(holder.iv_pic);
        holder.tv_title.setText(bean.getTitle());
        holder.tv_likes.setText(bean.getLikes());
        holder.tv_price.setText("￥"+bean.getPrice());
        return convertView;
    }

    public class ViewHolder{
        private ImageView iv_pic;
        private TextView tv_title,tv_likes,tv_price;
    }
}
